export const $qiniuUrl = "http://qiniu.warm-ehome.com/"

// export const serverUrl = "http://oa.warm-ehome.com"
export const serverUrl = "http://oatest.warm-ehome.com"
export const h5Url = "http://oa.warm-ehome.com/xiaijia/#/pages/home/home"
// export const serverUrl = "http://123.56.196.140:8090"
// export const h5Url = "http://106.75.246.44:9000/xiaijia/#/pages/home/home"

// export const h5Url = "http://192.168.80.138:8080/xiaijia/#/pages/home/home"
// export const h5Url = "http://localhost:8080/xiaijia/#/pages/home/home"

const install = (Vue, vm) => {

  Vue.prototype.$getImageUrl = function(url) {
    return $qiniuUrl + url;
  }

  Vue.prototype.$isWeixin = function() {
    let ua = window.navigator.userAgent.toLowerCase();
    // console.log(ua)
    if (ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_') {
      return true;
    } else {
      return false;
    }
  }

  Vue.prototype.$getRemoteUrl = function(url) {
    return $qiniuUrl + url;
  }

  Vue.prototype.$getRemotePdfUrl = function(url) {
    return serverUrl + 'AutioPdf/' + url
  }

  Vue.prototype.$getH5Url = function() {
    return h5Url;
  }

  Vue.prototype.$setTitle = function(title) {
      uni.setNavigationBarTitle({
        title: title
      })
    },


    Vue.prototype.$preview = function(url, current) {

      if (typeof(url) == 'object') {
        uni.previewImage({
          urls: url.map(item => Vue.prototype.$getImageUrl(item)),
          indicator: 'default',
          current: current
        })
      } else {
        uni.previewImage({
          urls: [Vue.prototype.$getImageUrl(url)]
        })
      }
    }

  Vue.prototype.$openFile = (url) => {
    uni.downloadFile({
      url: url,
      success: function(res) {
        let filePath = res.tempFilePath;
        uni.openDocument({
          filePath: filePath,
          success: function(res) {
            console.log('打开文档成功');
          }
        });
      },
      fail: function(res) {
        uni.previewImage({
          urls: [Vue.prototype.$getImageUrl(url)]
        })
      }
    });
  }
}

export default {
  install
};